/*
 * $Id: ExecuteCommand.java 471754 2006-11-06 14:55:09Z husted $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.bosch.in.rtp1.ept.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.chain.commands.ExecuteCommand;
import org.apache.struts.chain.contexts.ActionContext;
import org.apache.struts.chain.contexts.ServletActionContext;

import com.bosch.in.rtp1.ept.constant.CommonConstants;
import com.bosch.in.rtp1.ept.model.dto.Link;
import com.bosch.in.rtp1.ept.util.ConverterUtility;
import com.bosch.in.rtp1.ept.util.ManagerFactory;

/**
 * <p>Invoke the appropriate <code>Command</code> for this request.  If the
 * context's <code>ActionConfig</code> has no <code>command</code> property
 * defined, no action will be taken.  If the specified command cannot be
 * found, a warning will be logged, but processing will continue.  Depending
 * on how the chain is configured, this can be used in place of an
 * <code>Action</code> or as a method of performing pre-processing. </p>
 *
 * <p>If used instead of an action, the command which is looked up should put
 * an ActionForward into the context, unless it has already dealt with the
 * response.</p>
 *
 * @version $Id: ExecuteCommand.java 471754 2006-11-06 14:55:09Z husted $
 */
public class ChainExecuteCommand extends ExecuteCommand {
    // ------------------------------------------------------ Instance Variables

    /**
     * Provide Commons Logging instance for this class.
     */
    private static final Log LOG = LogFactory.getLog(ChainExecuteCommand.class);

    // ---------------------------------------------------------- Public Methods

    /**
     * <p>If the <code>context</code> is "valid", lookup a command and execute
     * it.</p>
     * This method is override to acts as chain of responsibility to get common values which are
     * used by almost pages.
     * 
     * @param actionCtx The <code>Context</code> for the current request
     * @return the result of the lookup command's <code>execute</code> method,
     *         if executed, or <code>false</code> if it was not executed.
     * @throws Exception on any error
     */
    public boolean execute(ActionContext actionCtx)
        throws Exception {
    	ServletActionContext saContext = (ServletActionContext) actionCtx;

        HttpServletRequest request = saContext.getRequest();
        
        LOG.debug("Get link list");
        // Select external links and put them into common request attribute
    	List<Link> linkList = ManagerFactory.getInstance().getLinkListManager().getLinkList();
    	request.setAttribute(CommonConstants.LINK_LIST, linkList);
    	
        return super.execute(actionCtx);
    }

}
